<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('福利变动')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>
    <th:block th:include="include :: container-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" name="allId" id="allId"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:benefitbase:add">
                <i class="fa fa-plus"></i> 添加员工
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:welfareopen:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger" onclick="removeAllIslock()"
               shiro:hasPermission="system:benefitbase:remove">
                <i class="fa fa-remove"></i> 删除
            </a>

            <a class="btn btn-primary" onclick="inspect()"
               shiro:hasPermission="system:welfareopen:edit">
                <i class="fa fa-edit"></i> 确认检查
            </a>
            <a class="btn btn-danger" onclick="cancel()"
               shiro:hasPermission="system:benefitbase:remove">
                <i class="fa fa-remove"></i> 取消确认
            </a>

            <a class="btn btn-warning" onclick="handle()" shiro:hasPermission="system:benefitbase:export">
                <i class="fa fa-download"></i> 变动处理
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<th:block th:include="include :: hr-help-js"/>
<th:block th:include="include :: datetimepicker-js"/>

<script th:inline="javascript">
    var prefix = ctx + "welfare/welfareChange";


    function inspect() {
        var cSP_BeneChangeCheck = "cSP_BeneChangeCheck";
        var allId = "";
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id
            } else {
                allId += row[i].id + ","

            }
        }
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        } else {
            $.ajax({
                async: false,
                url: prefix + "/changeProcedure",
                data: {
                    allId: allId,
                    procedure: cSP_BeneChangeCheck

                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        $("#allId").val(allId);
                        $.modal.alertWarning("操作成功！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else if (data.code == 500) {
                        $.modal.alertWarning("服务器繁忙！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else {
                        $.modal.alertWarning(data.message);
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }
                },

            });
        }
    }

    function cancel() {
        var cSP_BeneChangeCancel = "cSP_BeneChangeCancel";
        var allId = "";
        var row = $("#bootstrap-table").bootstrapTable('getSelections');

        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id
            } else {
                allId += row[i].id + ","

            }
        }

        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        } else {
            $.ajax({
                async: false,
                url: prefix + "/changeProcedure",
                data: {
                    allId: allId,
                    procedure: cSP_BeneChangeCancel

                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        $.modal.alertWarning("操作成功！");
                        $("#allId").val('');
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else if (data.code == 500) {
                        $.modal.alertWarning("服务器繁忙！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else {
                        $.modal.alertWarning(data.message);
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }

                },

            });
        }
    }

    function handle() {
        var cSP_BeneChangeStart = "cSP_BeneChangeStart";
        var allId = "";
        var row = $("#bootstrap-table").bootstrapTable('getSelections');

        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id
            } else {
                allId += row[i].id + ","

            }
        }

        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        } else {
            $.ajax({
                async: false,
                url: prefix + "/changeProcedure",
                data: {
                    allId: allId,
                    procedure: cSP_BeneChangeStart
                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        $.modal.alertWarning("操作成功！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else if (data.code == 500) {
                        $.modal.alertWarning("服务器繁忙！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else {
                        $.modal.alertWarning(data.message);
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }

                },
            });
        }
    }

    $(function () {
        var options = {
            code: "id",
            uniqueId: "id",
            url: prefix + '/list',
            height: $(window).height() - 120,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            modalName: "福利缴纳变动",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号'
                },
                {
                    field: 'badge',
                    title: '工号'
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'compName',
                    title: '公司名称'
                },
                {
                    field: 'depName',
                    title: '部门名称'
                },
                {
                    field: 'jobName',
                    title: '工作岗位'
                },
                {
                    field: 'benefitStatusName',
                    title: '原缴纳状态'
                },
                {
                    field: 'newBenefitStatusName',
                    title: '新缴纳状态'
                },
                {
                    field: 'benefitCityName',
                    title: '原社保缴纳地区'
                },
                {
                    field: 'newBenefitCityName',
                    title: '新社保缴纳地区'
                },
                {
                    field: 'accuCityName',
                    title: '原公积金缴纳地区'
                },
                {
                    field: 'newAccuCityName',
                    title: '新公积金缴纳地区'
                },
                {
                    field: 'effectdate',
                    title: '生效日期'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'regbyName',
                    title: '登记人'
                },
                {
                    field: 'regtime',
                    title: '登记时间'
                },
                {
                    field: 'initialized',
                    title: '？确认',
                    formatter: function (value, row, index) {
                        if (row.initialized == 1) {
                            return '<i class=\"fa fa-toggle-on text-info fa-2x\" ></i> ';
                        } else {
                            return '<i class=\"fa fa-toggle-off text-info fa-2x\" ></i> ';
                        }
                    }
                },
                {
                    field: 'initializedbyName',
                    title: '确认人'
                },
                {
                    field: 'initializedTime',
                    title: '确认时间'
                },

            ]
        };
        $.table.init(options);
    })
</script>
</body>
</html>